import React, { Component } from 'react';
import '../asserts/css/login.css'
import {Login as login} from '../request/login'
class Login extends Component {
     state={
        phone:"",
        password:""
     }
     toLogin()
     {
         let user = {...this.state}
       login(user).then(res=>{
           if(res.code === 200)
           {
               console.log(res)
               let loginData = res.list;
               console.log(loginData)
               localStorage.setItem('logindata',JSON.stringify(loginData))
            this.props.history.push("/index")
           }
       })
     }
    render() {
        let {phone,password} = this.state
        return (
            <>
                <div className="page-title">会员登录</div>
                <div className="container">
                    <div className="logo"></div>
                    <div className="form">

                        <div className="form-group">
                            <input type="text" placeholder="手机号" value={phone} onChange={(event)=>{this.setState({phone:event.target.value})}}/>
                        </div>
                        <div className="form-group">
                            <input type="password" placeholder="密码" value={password} onChange={(event)=>{this.setState({password:event.target.value})}}/>
                        </div>
                        <div className="form-group">
                            <button className="btn-gray" onClick={this.toLogin.bind(this)}>登录</button>
                        </div>
                    </div>
                </div>
            </>
        );
    }
}

export default Login;